home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / BGUI11c.lha / demos / window.c < prev    next >
C/C++ Source or Header  |  1994-08-19  |  6KB  |  159 lines

  1. ;/* Execute me to compile with DICE V3.0
  2. dcc window.c -proto -mi -ms -mRR -lbgui
  3. quit
  4. */
  5. /*
  6. **         $RCSfile: window.c,v $
  7. **      Description: Simple demonstration of handling IDCMP
  8. **                   events with the BGUI window class.
  9. **        Copyright: (C) Copyright 1994 Jaba Development.
  10. **                   (C) Copyright 1994 Jan van den Baard.
  11. **                   All Rights Reserved.
  12. **
  13. **          $Author: jaba $
  14. **        $Revision: 1.2 $
  15. **            $Date: 1994/08/03 11:42:08 $
  16. **/
  17.  
  18. #include <libraries/bgui.h>
  19. #include <libraries/bgui_macros.h>
  20. #include <libraries/gadtools.h>
  21.  
  22. #include <clib/alib_protos.h>
  23.  
  24. #include <proto/exec.h>
  25. #include <proto/bgui.h>
  26. #include <proto/intuition.h>
  27.  
  28. #include <stdio.h>
  29. #include <stdlib.h>
  30.  
  31. /*
  32. **      Library base pointer.
  33. **      NOTE: The intuition.library is opened by DICE
  34. **      it's auto-init code.
  35. **/
  36. struct Library                  *BGUIBase;
  37.  
  38. /*
  39. **      Object ID's.
  40. **/
  41. #define ID_QUIT                 1
  42.  
  43.  
  44. int main( int argc, char *argv[] )
  45. {
  46.         struct Window           *window;
  47.         Object                  *WO_Window, *GO_Quit, *GO_Status;
  48.         ULONG                    signal = 0, rc, tmp = 0;
  49.         BOOL                     running = TRUE;
  50.  
  51.         /*
  52.         **      Open the library.
  53.         **/
  54.         if ( BGUIBase = OpenLibrary( BGUINAME, BGUIVERSION )) {
  55.                 /*
  56.                 **      Create the window object.
  57.                 **/
  58.                 WO_Window = WindowObject,
  59.                         WINDOW_Title,           "Window Demo",
  60.                         WINDOW_SizeGadget,      FALSE,
  61.                         WINDOW_MasterGroup,
  62.                                 VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ),
  63.                                         StartMember, GO_Status = InfoFixed( NULL, ISEQ_C "Window Demo\n(C) Copyright 1993-1994 Jaba Development", NULL, 2 ), EndMember,
  64.                                         StartMember,
  65.                                                 HGroupObject,
  66.                                                         VarSpace( 50 ),
  67.                                                         StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  68.                                                         VarSpace( 50 ),
  69.                                                 EndObject,
  70.                                         EndMember,
  71.                                 EndObject,
  72.                 EndObject;
  73.  
  74.                 /*
  75.                 **      Object created OK?
  76.                 **/
  77.                 if ( WO_Window ) {
  78.                         /*
  79.                         **      Assign a key to the button.
  80.                         **/
  81.                         tmp = GadgetKey( WO_Window, GO_Quit,  "q" );
  82.                         /*
  83.                         **      OK?
  84.                         **/
  85.                         if ( tmp ) {
  86.                                 /*
  87.                                 **      try to open the window.
  88.                                 **/
  89.                                 if ( window = WindowOpen( WO_Window )) {
  90.                                         /*
  91.                                         **      Obtain it's wait mask.
  92.                                         **/
  93.                                         GetAttr( WINDOW_SigMask, WO_Window, &signal );
  94.                                         /*
  95.                                         **      Event loop...
  96.                                         **/
  97.                                         do {
  98.                                                 Wait( signal );
  99.                                                 /*
  100.                                                 **      Handle events.
  101.                                                 **/
  102.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  103.                                                         /*
  104.                                                         **      Evaluate return code.
  105.                                                         **/
  106.                                                         switch ( rc ) {
  107.  
  108.                                                                 case    WMHI_CLOSEWINDOW:
  109.                                                                 case    ID_QUIT:
  110.                                                                         running = FALSE;
  111.                                                                         break;
  112.  
  113.                                                                 case    WMHI_INACTIVE:
  114.                                                                         SetAttrs( WO_Window, WINDOW_Title, "Window de-activated", TAG_END );
  115.                                                                         break;
  116.  
  117.                                                                 case    WMHI_ACTIVE:
  118.                                                                         SetAttrs( WO_Window, WINDOW_Title, "Window activated", TAG_END );
  119.                                                                         break;
  120.                                                         }
  121.                                                 }
  122.                                         } while ( running );
  123.                                 } else
  124.                                         puts ( "Could not open the window" );
  125.                         } else
  126.                                 puts( "Could not assign gadget keys" );
  127.                         /*
  128.                         **      Disposing of the window object will
  129.                         **      also close the window if it is
  130.                         **      already opened and it will dispose of
  131.                         **      all objects attached to it.
  132.                         **/
  133.                         DisposeObject( WO_Window );
  134.                 } else
  135.                         puts( "Could not create the window object" );
  136.                 CloseLibrary( BGUIBase );
  137.         } else
  138.                 puts( "Unable to open the bgui.library" );
  139.  
  140.         return( 0 );
  141. }
  142.  
  143. #ifdef _DCC
  144. int wbmain( struct WBStartup *wbs )
  145. {
  146.         return( main( 0, NULL ));
  147. }
  148. #endif
  149.  
  150. /*
  151.  *      $Log: window.c,v $
  152.  * Revision 1.2  1994/08/03  11:42:08  jaba
  153.  * Switched from clib/ to proto/.
  154.  *
  155.  * Revision 1.1  1994/06/20  16:43:03  jaba
  156.  * Initial revision
  157.  *
  158.  */
  159.